import Mock from "mockjs";
import type { MockMethod } from "vite-plugin-mock";

interface User {
  id: number;
  name: string;
  age: number;
  gender: string;
}

const userList: User[] = Mock.mock({
  "list|19": [
    {
      "id|+1": 1010000 + 1,
      creationDate: "@datetime('yyyy-MM-dd HH:mm:ss')",
      updateDate: "@datetime('yyyy-MM-dd HH:mm:ss')",
      name: "@cname",
      "age|18-60": 1,
      "gender|1": ["男", "女"],
      "department": "研发部",
      address: "广东省深圳市龙岗区坂田街道上雪村西三巷二号804室",
      imageUrl: "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
      delivery: false
    },
  ],
}).list;

export default [
  {
    url: "/api/product/brand/page",
    method: "get",
    response: ({ query }) => {
      let { currentPage, pageSize } = query;
      let start = Number((currentPage - 1) * pageSize);
      console.log("[VSCode].终端打印.start:", start);
      let end = Number(Number(start) + Number(pageSize));
      console.log("[VSCode].终端打印.end:", end);
      let data = userList.slice(start, end);
      return {
        code: 200,
        data: {
          total: userList.length,
          records: data,
        },
      };
    },
  },
  {
    url: "/api/product/brand/save",
    method: "post",
    response: ({ body }) => {
      const { address, age, department, creationDate, gender, id, imageUrl, name, updateDate, delivery } = body
      console.log("[VSCode].终端打印.address:", address)
      const newData = {
        "address": address,
        "age": age,
        "department": department,
        "creationDate": creationDate,
        "gender": gender,
        "id": 1010000 + (userList.length + 1),
        "imageUrl": imageUrl,
        "name": name,
        "updateDate": updateDate,
        "delivery": delivery
      }
      console.log("[VSCode].终端打印.newData:", newData)
      newData.id = 1010000 + (userList.length + 1)
      userList.push(newData)
      return {
        code: 200,
        data: {
          total: userList.length,
          records: userList,
        },
      };
    },
  },
  {
    url: "/api/product/brand/edit",
    method: "post",
    response: ({ body }) => {
      const { address, age, department, creationDate, gender, id, imageUrl, name, updateDate, delivery } = body
      console.log("[VSCode].终端打印.id:", id)
      const newData = {
        "address": address,
        "age": age,
        "department": department,
        "creationDate": creationDate,
        "gender": gender,
        "id": id,
        "imageUrl": imageUrl,
        "name": name,
        "updateDate": updateDate,
        "delivery": delivery
      }
      console.log("[VSCode].终端打印.newData:", newData)
      newData.id = 1010000 + (userList.length + 1)
      userList.push(newData)
      return {
        code: 200,
        data: {
          total: userList.length,
          records: userList,
        },
      };
    },
  }
] as MockMethod[];
